import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:flutter_test1/db/db.dart';
import 'package:flutter_test1/helper/web3_utils.dart';
import 'package:flutter_test1/home/home_view.dart';
import 'package:flutter_test1/web_view.dart';
import 'package:get/get_navigation/src/root/get_material_app.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await DbManager().database;
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: const Size(375, 812),
      builder: (context, child) {
        return GetMaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(
            colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
            useMaterial3: true,
          ),
          home: const MyHomePage(title: 'Flutter Demo Home Page'),
          builder: FlutterSmartDialog.init(),
        );
      }
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});
  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _selectedIndex = 0;
  // 各个页面的列表
  final List<Widget> _pages = [
    HomePage(),
    ExchangePage(),
    FinancePage(),
    WebViewPage()
  ];

  void _onItemTapped(int index) {
    setState(() {
      _selectedIndex = index;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      // appBar: AppBar(
      //   backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      //   title: Text('首页'),
      // ),
      body:IndexedStack(
        index: _selectedIndex,
        children: _pages,
      ),
      bottomNavigationBar: BottomNavigationBar(
        unselectedItemColor: Colors.green,
        selectedLabelStyle: TextStyle(color: Colors.blueAccent),
        unselectedLabelStyle: TextStyle(color: Colors.green, fontSize: 14),
        items: const <BottomNavigationBarItem>[
          BottomNavigationBarItem(
            icon: Icon(Icons.home),
            label: '首页',

          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.swap_horiz),
            label: '兑换',
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.monetization_on),
            label: '理财',
            // backgroundColor: Colors.red
          ),
          BottomNavigationBarItem(
            icon: Icon(Icons.explore),
            label: '发现',
          ),
        ],
        currentIndex: _selectedIndex,
        selectedItemColor: Colors.blue,
        onTap: _onItemTapped,
      ),
    );
  }
}




// class HomePage extends StatelessWidget {
//   @override
//   Widget build(BuildContext context) {
//     Web3Utils.init(); // 初始化 Web3
//     return Scaffold(
//       appBar: AppBar(
//         title: Text('示例页面'),
//       ),
//       body: Center(
//         child: Column(
//           mainAxisAlignment: MainAxisAlignment.center,
//           children: [
//             Text('首页'),
//             SizedBox(height: 20), // 添加一些间距
//             ElevatedButton(
//               onPressed: () {
//                 // 按钮点击事件处理
//                 print('按钮被点击');
//                 Web3Utils.add();
//                 // 这里可以添加其他逻辑
//               },
//               child: Text('点击我'),
//             ),
//           ],
//         ),
//       ),
//     );
//   }
// }

class ExchangePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(child: Text('兑换'));
  }
}

class FinancePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Center(child: Text('理财'));
  }
}
//
// class DiscoverPage extends StatelessWidget {
//   @override
//   Widget build(BuildContext context) {
//     return Center(child: Text('发现'));
//   }
// }
